

var token =getItem('token');
var userId= '';
if(token==null){
	window.location.href="login.html";
}
//退出登录
$('#confirmBtn').click(function(){
	document.getElementById("confirmBtn").addEventListener('tap', function() {
		var btnArray = ['取消', '确认'];
		mui.confirm('是否要退出登录？', '', btnArray, function(e) {
			if (e.index == 1) {
				$.ajax({
					url:'/user/userLogout.json',
					dataType:'json',
					data:{
						token:getItem('token'),
					},
					success:function(data){
						removeItem('token');
						window.location.href="index.html";
					}
				})
			} else {

			}
		})
	});
})

//获取基本信息
$(function(){
	$.ajax({
		url:'/user/getUserHeadData.json',
		dataType:'json',
		type:'post',
		data:{
			token:token,
		},
		success:function(data){
			if(data.code==-1){
				window.location.href="login.html";
			}
			if(data.code==1){
				var data = data.datas;
				userId = data.userId;
				setItem('UserTypeValue',data.UserTypeValue);

				if(data.countCard==0){
					$('#card').html('绑定银行卡');
					$('#cardBox').attr('href','integral-withdraw1.html?card=false');
				}else{
					$('#card').html('我的银行卡');
					$('#cardBox').attr('href','mycard.html');
				}
				if(data.UserTypeValue==5){
					var href = "apply-makeorders.html?shopId="+data.ShopId;
					$('#record').html('做单记录');
					$('#applymakeorder').attr('href',href);
					$('#applymakeorder').show();
					$('#makeorderDetail').show();
                    $('#makeorderDetail2').show();
					$('#info').html('商家须知');
					$('#infoBox').attr('href','business-information.html');
				}else if(data.UserTypeValue==2){
					var href = "outline-makeorders.html?shopId="+data.ShopId;
					$('#makeorder').attr('href',href);
					$('#makeorder').show();
					$('#makeorderDetail').show();
                    $('#makeorderDetail2').show();
					$('#makeorderCheck').show();
					//$('.personal-top-box .userBox li').css('width','25%');
					$('#cdd').html(data.SddNum+'个');
					//$('#dingdang').show();
					$('#info').html('商家须知');
					$('#infoBox').attr('href','business-information.html');
				}else{
					$('#info').html('用户须知');
					$('#infoBox').attr('href','user-infomation.html');
				}
				$('#userName').html(data.RealName);
				$('.delevel').html(data.UserType);
				var balance = data.AccountMoney;
				//if (balance > 10000) {
				//	balance = (balance / 10000).toFixed(2) + '万';
				//}
				$('#balance').html(balance+"积分");
				$('#dd').html(data.CddNum+"个");
				$('.avatar-box img').attr('src',data.Avotorr);
				if(data.UserTypeValue==1){
					setItem('userType','1');
				}
				//获取订单数量
                $.ajax({
                    url:'/zuoDanC/numByOrderState.json',
                    dataType:'json',
                    data:{
                        token:getItem('token'),
                    },
                    type:'post',
                    success:function (data) {
                        if(data.datas.userTypeValue==2||data.datas.userTypeValue==5){
                            //待发货
                            if(data.datas.sOrderNoDelivery>0){
                                $('#send2_num').html(data.datas.sOrderNoDelivery)
                                $('#send2_num').show();
                            }
                            //待做单
                            if(data.datas.sOrderAudit>0){
                                $('#reseive2_num').html(data.datas.sOrderAudit)
                                $('#reseive2_num').show();
                            }
                        }else{

                        }
                        //订单待发货
                        if(data.datas.uOrderNoDelivery>0){
                            $('#send_num').html(data.datas.uOrderNoDelivery)
                            $('#send_num').show();
                        }
                        //待收获
                        if(data.datas.uOrderRegeipt>0){
                            $('#receive_num').html(data.uOrderRegeipt)
                            $('#receive_num').show();
                        }
                        //待评价
                        if(data.datas.uOrderComment>0){
                            $('#comment_num').html(data.datas.uOrderComment)
                            $('#comment_num').show();
                        }
                    }
                })
			}
		}
	})
})

$('#tuiguangma').click(function () {
	window.location.href="authorize.html?userId="+userId
})

//获取是否有未读消息
$(function(){
	$.ajax({
		url:'/messagesC/countNotReadMessages.json',
		dataType:'json',
		data:{
			token:getItem('token'),
		},
		type:'post',
		success:function(data){
			if(data.code==1){
				var data = data.datas;
				if(data.count==0){
					$('#ifRead').hide();
				}else{
					$('#ifRead').show();
				}
			}
		}
	})
})

//我的订单
$('.order-title').click(function () {
	window.location.href="userOrder_v2.html?zuoDanStateValue="
})

//待发货
$('#await_send').click(function () {
	window.location.href="userOrder_v2.html?zuoDanStateValue=4"
})

//待收货
$('#await_reseive').click(function () {
    window.location.href="userOrder_v2.html?zuoDanStateValue=5"
})

//待评价
$('#await_comment').click(function () {
    window.location.href="userOrder_v2.html?zuoDanStateValue=2"
})

//商家订单
$('#makeorderDetail').click(function () {
	window.location.href="shopOrder_v2.html";
})

//待发货
$('#await_send2').click(function () {
    window.location.href="shopOrder_v2.html?zuoDanStateValue=4"
})

//待收货
$('#await_reseive2').click(function () {
    window.location.href="shopOrder_v2.html?zuoDanStateValue=5"
})

//待评价
$('#await_comment2').click(function () {
    window.location.href="shopOrder_v2.html?zuoDanStateValue=2"
})


